package org.novelhibernate.core;

import java.sql.Connection;
import java.sql.SQLException;

import org.novelhibernate.core.transaction.Transaction;


public interface JdbcTemplate {

	
	public Transaction beginPlainTransaction (boolean autoCommit,
			int transactionIsolation, boolean isRecordResult) throws SQLException;
	
	
	
	/**
	 * This is used when there is a given connection, normally acquire from Hibernate
	 * , do this can make sure that the JDBC statements are share the same transaction with Hibernate, in which case
	 * improve the consistency of system and guarantee AICD
	 * 
	 * @param conn
	 * @param isRecordResult
	 * @return the transaction created for current thread
	 * @throws SQLException
	 */
	public Transaction beginConnectionRelatedTransaction (Connection conn, boolean isRecordResult) 
	        throws SQLException;
	
	/**
	 * This is used when Spring is used in the environment, all the transactions, sessions are managed by HibernateTransactionManager or
	 * JdbcTransactionManager, do this in order to share the same transaction that managed by Spring when using novelhibernate, in order to
	 * provide AICD
	 * @param dataSource this object could be either SessionFactory (when use Hibernate) or DataSource (when use JdbcTemplate)
	 * @param isRecordResult
	 * @return the transaction created for current thread
	 * @throws Throwable
	 */
	public Transaction beginSpringManagedTransaction (Object dataSource, boolean isRecordResult) 
            throws Throwable;
	
	
}
